﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace QLKS
{
    public partial class DMP : Form
    {
        public Mysql qmysql = new Mysql();
        public int ptdx;
        public Button button;
        public static int ID;
        public static int BTName;
        public DMP()
        {
            InitializeComponent();
           
        }
        
       
        private void btn_On_Click(object sender, EventArgs e)
        {
            Button btc = (Button)sender;
            BTName = Convert.ToInt32(btc.Name); 
            ThanhToan thanhtoan = new ThanhToan();
            thanhtoan.MdiParent = this.ParentForm;
            thanhtoan.Show();
            this.Close();
        }

        private void btn_Off_Click(object sender, EventArgs e)
        {
            Button btc = (Button)sender;
            Program.TENP = this.qmysql.GetNameRoomByID(btc.Name); 
            PNP pnp = new PNP();
            pnp.MdiParent = this.ParentForm;
            pnp.Show();
            this.Close();
        }
       
        private void DMP_Load(object sender, EventArgs e)
        {
         //   MakeButton();
           
        }

        private void DMP_Activated(object sender, EventArgs e)
        {
            MakeButton();
        }

       
       
       public void MakeButton ()
        {
            this.ptdx = (this.Width / 110) - 1;
            int ptd = Convert.ToInt32(this.ptdx);
           // Lấy tổng số phòng;
            int soluongphong = qmysql.TotalRoom();
            int xposition = 20, yposition = 30;
            for (int i = 0; i < soluongphong; i++)
            {
                ID = qmysql.GetIDRoom(i);
                int IDRoom = qmysql.GetIDRoom(i);
                bool roomm = qmysql.GetMRoom(IDRoom);
                bool isfull = qmysql.GetStatusRoom(IDRoom);
                bool isvip = qmysql.GetVIPRoom(IDRoom);
                this.button = new Button();
                this.button.Width = 110;
                this.button.Height = 65;
                this.button.Name = ID.ToString();
                this.button.Text = qmysql.GetNameRoom(i).ToString();
                if (i % ptd == 0 && i > 0)
                {
                    yposition = yposition + 75;
                    xposition = 20;
                }
                this.button.Location = new Point(xposition + ((i % ptd) * 110), yposition);
                xposition = xposition + 10;
                // Thay doi mau va icon cho 2 loai phong;
                if (roomm)
                {
                    // Phong sua chua;
                    this.button.Image = QLKS.Properties.Resources.ide_32x32;
                    this.button.BackColor = Color.Silver;
                    this.button.FlatAppearance.BorderColor = Color.Silver;
                    this.button.Enabled = false;
                }
                else if (isfull)
                {
                    // Phòng có khách;
                    if (isvip)
                    {
                        // Phòng VIP;
                        this.button.Image = QLKS.Properties.Resources._1396161432_star;
                    }
                    else
                    {
                        // Phòng Thường
                        this.button.Image = QLKS.Properties.Resources.employee_32x32;
                    }
                    this.button.BackColor = Color.FromArgb(255, 128, 128);
                    this.button.FlatAppearance.BorderColor = Color.FromArgb(192, 0, 0);
                    this.button.Click += new EventHandler(btn_On_Click);

                }
                else
                {
                    // Phòng còn trống;
                    if (isvip)
                    {
                        // Phòng VIP;
                        this.button.Image = QLKS.Properties.Resources._1396161432_star;
                    }
                    else
                    {
                        // Phòng Thường
                        this.button.Image = QLKS.Properties.Resources.customer_32x32;
                    }
                    this.button.BackColor = Color.FromArgb(128, 255, 128);
                    this.button.FlatAppearance.BorderColor = Color.FromArgb(0, 192, 0);
                    this.button.Click += new System.EventHandler(btn_Off_Click);

                }

                this.button.FlatStyle = FlatStyle.Flat;
                this.button.FlatAppearance.BorderSize = 1;
                this.Controls.Add(this.button);
                this.button.ImageAlign = ContentAlignment.TopCenter;
                this.button.TextAlign = ContentAlignment.BottomCenter;

            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            DSNV ds = new DSNV();
            ds.Show();
        }
       
       


       




        

    }
}
